require 'digest/sha1'
class Alumno < ActiveRecord::Base
	include Compartido
	extend Compartido
	
	file_column :imagen, :magick => { :geometry => "50x50" }
	
  validates_presence_of :cuenta, :username, :password, :salt, :nombre, :ap_materno, :ap_paterno,
   :semestre, :carrera, :message => "no puede ser vacío"
  validates_numericality_of :cuenta, :semestre, :message => "debe ser numérico"
  validates_format_of :correo, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :message => "no es válido"
  attr_accessor :clave_confirmation 
  validates_confirmation_of :clave, :message => "debe coincidir con el campo password"
  
  has_many :citas
  
  def self.authenticate(username, clave) 
    user = Alumno.find_by_username(username) 
    if user 
      expected_password = encrypted_password(clave, user.salt) 
      if user.password != expected_password 
        user = nil 
      end 
    end
    user 
  end 
  
  def nombre_completo
  	self.nombre + " " + self.ap_paterno + " " + self.ap_materno
  end
end
